#pragma once

class CRandom
{
public:
	CRandom()  { numcalls=0; };
	virtual ~CRandom() {};
	
public:
	static BYTE getUint8()
	{ 
		double ratio=(double)rand()/(double)(RAND_MAX+1.0);
		return (BYTE)(256.0*ratio); 
	}
	
	WORD  getUint16()
	{
		DWORD seed;
		BYTE  byte;
		WORD retval=0;
		
		numcalls++;
		seed = (DWORD)time(NULL);
		seed += numcalls;
		seed += clock();
		srand(seed);
		byte = getUint8();
		retval |= ((DWORD)byte);
		byte = getUint8();
		retval |= (((DWORD)byte)<<8);
		
		return retval;
	}

	DWORD getUint32()
	{
		DWORD seed;
		BYTE   byte;
		DWORD retval=0;
		
		if(numcalls==0)
		{
			numcalls++;
			seed = (DWORD)time(NULL);
			seed *= numcalls;
			seed -= clock();
			seed += (long)this;
			srand(seed);
		}
		byte = getUint8();
		retval |= ((DWORD)byte);
		byte = getUint8();
		retval |= (((DWORD)byte)<<8);
		byte = getUint8();
		retval |= (((DWORD)byte)<<16);
		byte = getUint8();
		retval |= (((DWORD)byte)<<24);
		
		return retval;
	}

	DWORD getUint32(DWORD start, DWORD end)
	{
		if(start == end)
			return start;
		else
			return (start + getUint32()%(end - start));
	}

private:
	int numcalls;
};













